package org.csu.petstore.ssm.service.impl;

import org.csu.petstore.ssm.entity.Account;
import org.csu.petstore.ssm.entity.Consignee;
import org.csu.petstore.ssm.persistence.AccountMapper;
import org.csu.petstore.ssm.persistence.ConsigneeMapper;
import org.csu.petstore.ssm.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("AccountService")
public class AccountServiceImpl implements AccountService {

    @Autowired
     private AccountMapper accountMapper;

    @Autowired
    private ConsigneeMapper consigneeMapper;


    @Override
    public Account getAccount(String username, String password) {
      return accountMapper.getAccountByUsernameAndPassword(username,password);
    }

    @Override
    public Account getAccountByUsername(String username) {
        return accountMapper.getAccountByUsername(username);
    }

    @Override
    public void insertAccount(Account account) {
        accountMapper.insertAccount(account);
        accountMapper.insertSignon(account);
        accountMapper.insertProfile(account);
    }

    @Override
    public void updateAccount(Account account) {
        accountMapper.updateAccount(account);
    }

    @Override
    public boolean selectAccountByUsername(String username) {
        return accountMapper.selectAccountByUsername(username);
    }

    @Override
    public boolean selectAccountByPassword(String password) {
        return accountMapper.selectAccountByPassword(password);
    }

    public List<Consignee> getConsignee(String username){
        return this.consigneeMapper.getConsigneeByUsername(username);
    }

}
